﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;

namespace LdCms.Web.Controllers.API.Institution.V1
{
    using LdCms.Common.Extension;
    using LdCms.EF.DbModels;
    using LdCms.IBLL.Institution;
    using LdCms.Web.Models;
    using LdCms.Web.Services;
    /// <summary>
    /// 公司资料管理接口：
    ///     1、公司资料（明细）
    ///        GET：institution/company/get?uuid=uuid
    /// 
    /// </summary>
    [ApiVersion("1.0")]
    [ControllerName("institution/company")]
    public class InstitutionCompanyController : BaseApiController
    {
        private readonly IBaseApiManager BaseApiManager;
        private readonly ICompanyService CompanyService;
        public InstitutionCompanyController(IBaseApiManager BaseApiManager, ICompanyService CompanyService) : base(BaseApiManager)
        {
            this.BaseApiManager = BaseApiManager;
            this.CompanyService = CompanyService;
        }

        [HttpGet]
        [ActionName("get")]
        public IActionResult GetCompanyPro(string uuid)
        {
            long logId = 0;
            try
            {
                logId = BaseApiManager.SaveLogs(uuid);
                string companyId = InterfaceAccount.CompanyID;
                var entity = CompanyService.GetCompanyPro(SystemID, companyId);
                if (entity == null)
                    return Error(logId, "not data！");
                var data = new
                {
                    company_name = entity.CompanyName.IIF(),
                    name = entity.NickName.IIF(),
                    tel = entity.Tel.IIF(),
                    fax = entity.Fax.IIF(),
                    phone = entity.Phone.IIF(),
                    email = entity.Email.IIF(),
                    address = entity.Address.IIF(),
                    description = entity.Description.IIF(),
                    state = entity.State.ToBool(),
                    date = entity.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")
                };
                return Success(logId, "ok", data);
            }
            catch (Exception ex)
            {
                return Error(logId, ex.Message);
            }
        }


    }
}